/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package clientside;

import client.gui.MainView;
import java.io.*;
import java.net.*;
import client.network.*;
import com.cse.p2p.common.CommonSettings;
import com.cse.p2p.database.ClientDatabase;
import java.awt.Toolkit;
import javax.swing.JFrame;
import javax.swing.UIManager;

/**
 *
 * @author TrungHieu
 */
public class ClientSide {

	public static int portServer = CommonSettings.SERVER_SERVERSOCKET;

	public static void main( String[] args ) {
		if ( args.length > 1 ) {
			CommonSettings.HOST_ADDRESS = args[0];
		}

		try {
//			ClientDatabase.openDatabase();
			ControlClientSide controlThread = new ControlClientSide();
			DataClientSide dataThead = new DataClientSide();
			controlThread.start();
			dataThead.start();
			new ClientControlTask_Client( CommonSettings.HOST_ADDRESS, portServer, null, null ).start();

			UIManager.setLookAndFeel( "com.seaglasslookandfeel.SeaGlassLookAndFeel" );
//			UIManager.setLookAndFeel( "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel" );
			Toolkit tk = Toolkit.getDefaultToolkit();
			MainView mainview = new MainView( controlThread, dataThead );
			mainview.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
			mainview.setSize( tk.getScreenSize().width - 400, tk.getScreenSize().height -200 );
			mainview.setLocationRelativeTo( null );
			mainview.setVisible( true );
			File tempFolder = new File( CommonSettings.DEFAULT_TEMP_FOLDER );
			if ( !tempFolder.exists() ) {
				tempFolder.mkdirs();
			}
		}
		catch ( Exception e ) {
			e.getCause().printStackTrace();
		}
		finally {
//			ClientDatabase.closeDatabase();
		}
	}
}
